import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import '../utils/constant/text_styles.dart';
import 'jr.dart';

ThemeData get defaultThemeData {
  TextTheme textTheme = TextTheme(
    titleLarge: JRTextStyles.title,
    titleSmall: JRTextStyles.subtitle,
    // 设置 textBaseline 是为了修复在v1.9.1中TextField的hint没有垂直居中的bug
    // 如果后期版本的引擎修复了此bug，可删除此项设置
    // 参考 TextField#build -> InputDecorator -> _InputDecoratorState#build -> #_getInlineStyle
    titleMedium: JRTextStyles.subhead,
    bodyMedium: JRTextStyles.body1,
    bodyLarge: JRTextStyles.body2,
    labelLarge: JRTextStyles.button,
    bodySmall: JRTextStyles.caption,
  );

  TextTheme primaryTextTheme = TextTheme(
    titleLarge: textTheme.titleLarge?.copyWith(color: JR.color.mainBackground),
    titleSmall: textTheme.titleSmall?.copyWith(color: JR.color.mainBackground),
    titleMedium:
        textTheme.titleMedium?.copyWith(color: JR.color.mainBackground),
    labelLarge: textTheme.labelLarge?.copyWith(color: JR.color.mainBackground),
    bodyMedium: textTheme.bodyMedium?.copyWith(color: JR.color.mainBackground),
    bodyLarge: textTheme.bodyLarge?.copyWith(color: JR.color.mainBackground),
    bodySmall: textTheme.bodySmall?.copyWith(color: JR.color.mainBackground),
  );

  Color disableColor = JR.color.tint;

  ThemeData theme = ThemeData(
    platform: TargetPlatform.iOS,
    brightness: JR.brightness,
    // primaryColorBrightness: JR.brightness,
    fontFamily: fontFamily,
    primaryColor: JR.color.mainBrand,
    // accentColor: JR.color.mainBrand,
    textSelectionTheme: TextSelectionThemeData(
      cursorColor: JR.color.mainBrand,
    ),
    hintColor: JR.color.tipsText,
    // backgroundColor: JR.color.mainBackground,
    scaffoldBackgroundColor: JR.color.mainBackground,
    unselectedWidgetColor: disableColor,
    disabledColor: disableColor,
    cardColor: JR.color.mainBackground,
    textTheme: textTheme,
    primaryTextTheme: primaryTextTheme,
    // toggleableActiveColor: JR.color.mainBrand,
    buttonTheme: ButtonThemeData(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(45),
      ),
      buttonColor: JR.color.mainBrand,
      disabledColor: JR.color.tint,
    ),
    cupertinoOverrideTheme: CupertinoThemeData(
      primaryColor: JR.color.mainBrand,
      brightness: JR.brightness,
      barBackgroundColor: JR.color.mainBackground,
      scaffoldBackgroundColor: JR.color.mainBackground,
    ),
    indicatorColor: JR.color.mainBrand,
    iconTheme: IconThemeData(size: 24, color: JR.color.mainText),
    primaryIconTheme:
        IconThemeData(size: 24, color: primaryTextTheme.titleLarge?.color),
    dialogTheme: DialogTheme(
      elevation: 0,
      backgroundColor: JR.color.maskColor,
    ),
  );

  return theme.copyWith(
    inputDecorationTheme: InputDecorationTheme(
        fillColor: disableColor,
        hintStyle: theme.textTheme.bodyMedium
            ?.copyWith(color: JR.color.mainText.withOpacity(0.2)),
        labelStyle: theme.textTheme.bodyMedium),
    appBarTheme: AppBarTheme(
      color: JR.color.card,
      systemOverlayStyle: JR.brightness == Brightness.dark
          ? SystemUiOverlayStyle.light
          : SystemUiOverlayStyle.dark,
      iconTheme: IconThemeData(
        color: JR.color.mainText,
        size: 24,
      ),
      titleTextStyle: JRTextStyles.title,
      actionsIconTheme: IconThemeData(
        color: JR.color.mainText,
        size: 24,
      ),
    ),
    tabBarTheme: TabBarTheme(
      indicatorSize: TabBarIndicatorSize.label,
      labelColor: JR.color.mainText,
      // labelStyle: theme.textTheme.headline6,
      labelPadding:
          const EdgeInsetsDirectional.only(start: 10.0, end: 10.0, bottom: 0.0),
      unselectedLabelColor: JR.color.tipsText,
      unselectedLabelStyle:
          theme.textTheme.titleMedium?.copyWith(color: JR.color.secondaryText),
    ),
    // toggleableActiveColor: JR.color.mainBrand,
  );
}
